const fs = require('fs').promises
//const path = require('path')
export const mapArr = (arr) => {
    return arr.reduce((map, item) => {
        map[item.id] = item
        return map;
    }, {})
}

export const objToArr = (obj) => {
    return Object.keys(obj).map(key => obj[key])
}

//读取文件
export const readFile = (path) => {
    return fs.readFile(path, 'utf-8')
}
//写入文件
export const writeFile = (path, content) => {
    return fs.writeFile(path, content, 'utf-8')
}
//重命名
export const renameFile = (path, newPath) => {
    return fs.rename(path, newPath)
}
//删除文件
export const deleteFile = (path) => {
    return fs.unlink(path)
}
export const getParentNode = (node, parentClassName) => {
    let currentEle = node
    while (currentEle !== null && currentEle !== undefined) {
        if (currentEle.classList && currentEle.classList.contains(parentClassName)) {
            return currentEle
        }
        currentEle = currentEle.parentNode
    }
    return false
}